//
//  ViewController.m
//  JsonTest
//
//  Created by apple on 15/12/28.
//  Copyright © 2015年 CXM. All rights reserved.
//

#import "ViewController.h"
#import "MD5Uncode.h"
#import "User.h"
#import "JKDBHelper.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *urlString = @"http://apis.baidu.com/chazhao/md5decod/md5decod?md5=e10adc3949ba59abbe56e057f20f883e";
    [[JSONHTTPClient requestHeaders] setValue:@"6f55e04d60541c59b7e119d8ed4801d9" forKey:@"apikey"];

    
   [JSONHTTPClient getJSONFromURLWithString:urlString completion:^(NSDictionary *json, JSONModelError *err) {
       
     MD5Uncode *md5d =   [[MD5Uncode alloc] initWithDictionary:json error:nil];
       
       NSLog(@"md5 %@",md5d.data.md5_src);
   }];
    
    // Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)insertOne:(id)sender {
    [self insertData];
}
- (IBAction)insertMore:(id)sender {
    [self insertMoreData];
}

-(void)insertData
{

    for (int i = 0; i < 1; i++) {
        User *user = [[User alloc] init];
        user.name = [NSString stringWithFormat:@"麻子%d",i];
        user.sex = @"男";
        user.age = 10+i;
        NSString * str = [user toJSONString];
        
        NSLog(@"水水水水 %@",str);
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            [user save];
        });
    }
}
-(void)insertMoreData
{

    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSMutableArray *array = [NSMutableArray array];
        for (int i = 0; i < 500; i++) {
            User *user = [[User alloc] init];
            user.name = [NSString stringWithFormat:@"李四%d",i];
            user.age = 10+i;
            user.sex = @"女";
            [array addObject:user];
        }
        [User saveObjects:array];
    });
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
